﻿// This code is released under the BSD license.
namespace PugLib.Threading
{
	using System;
	using System.Threading;

	public static class ThreadPoolHelper
	{
		public static bool QueueUserWorkItem<T>(T state, Action<T> callback)
		{
			return ThreadPool.QueueUserWorkItem(s => callback((T)s), state);
		}

		public static bool QueueUserWorkItem<Tin, Tout>(Tin state, Func<Tin, Tout> callback)
		{
			return ThreadPool.QueueUserWorkItem(s => callback((Tin)s), state);
		}

		public static void DoAsync<TResult>(this Func<TResult> f, Action<TResult> callback)
		{
			f.BeginInvoke(x => callback(f.EndInvoke(x)), null);
		}
	}
}